package zkk.com.mengqu.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import zkk.com.mengqu.R;
import zkk.com.mengqu.fragment.CircleFriendFragment;
import zkk.com.mengqu.fragment.KitchenEstimateFragment;
import zkk.com.mengqu.fragment.KitchenIntroFragment;

/**
 * Created by Administrator on 2017/4/3.
 * 厨房共享/预约
 */
public class KitchenOrderActivity extends FragmentActivity implements View.OnClickListener{
    private Context context;
    private ImageView back,share,collect;//返回,分享，收藏
    private TextView order;//预约厨房
    private List<Fragment> mFragmentList = new ArrayList<>();
    private TabLayout tableLayout;//导航栏
    private ViewPager viewPager;
    private ApnFragmentAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kitchen_order);
        context = getApplicationContext();
        initVIew();
    }

    public void initVIew(){
        back = (ImageView)findViewById(R.id.iv_back);
        share = (ImageView)findViewById(R.id.iv_share);
        collect = (ImageView)findViewById(R.id.iv_collect);
        order = (TextView)findViewById(R.id.tx_kitchen_order);

        tableLayout = (TabLayout)findViewById(R.id.tableLayout);
        viewPager = (ViewPager)findViewById(R.id.viewPager);

        mFragmentList.add(new KitchenIntroFragment());//厨房简介
        mFragmentList.add(new KitchenEstimateFragment());//厨房评价

        mAdapter = new ApnFragmentAdapter(getSupportFragmentManager());
        viewPager.setAdapter(mAdapter);
        tableLayout.setupWithViewPager(viewPager);
        tableLayout.setTabMode(TabLayout.MODE_FIXED);

        back.setOnClickListener(this);
        share.setOnClickListener(this);
        collect.setOnClickListener(this);
        order.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_back:
                finish();
                break;
            case R.id.iv_share:
                Toast.makeText(context , "分享", Toast.LENGTH_LONG).show();
                break;
            case R.id.iv_collect:
                Toast.makeText(context , "收藏", Toast.LENGTH_LONG).show();
                break;
            case R.id.tx_kitchen_order:
                Toast.makeText(context , "预约", Toast.LENGTH_LONG).show();
                break;
            default:
                break;
        }
    }

    private class ApnFragmentAdapter extends FragmentPagerAdapter {
        CharSequence[] TITLE = new CharSequence[]{"厨房简介","厨房评价"};

        public ApnFragmentAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return TITLE.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return TITLE[position];
        }
    }
}
